#include "StdAfx.h"

namespace Public
{
	Acad::ErrorStatus  AppendAndClose(AcDbObject* pObj, AcDbDatabase* pDataBase)
	{
		Acad::ErrorStatus es = Acad::eInvalidInput;
		if (NULL == pDataBase)
			pDataBase = acdbCurDwg();

		if (NULL == pObj)
		{
			return es;
		}

		if (!pObj->isKindOf(AcDbEntity::desc()))
		{
			return es;
		}

		AcDbBlockTableRecordPointer spBlkRecord(pDataBase->currentSpaceId(), AcDb::kForWrite);
		es = spBlkRecord.openStatus();
		if (Acad::eOk != es)
		{
			return es;
		}
		es = spBlkRecord->appendAcDbEntity((AcDbEntity*)pObj);
		if (Acad::eOk != es)
		{
			return es;
		}

		es = pObj->close();

		return es;
	}
}